package com.ruoyi.flow.entity.machine;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@Data
public class Flow {

    private String id;
    private String name;

    private List<State> states;

    private List<Event> events;

    private List<Condition> conditions;

    private List<Node> nodes;

    private List<Line> lines;

    public State getStateById(String id){
        if(states!=null && states.size()>0 && !StringUtils.isEmpty(id)){
            return states.stream().filter(x -> x.getId().equals(id)).findAny().orElse(null);
        }
        return null;
    }

    public Event getEventById(String id){
        if(events!=null && events.size()>0 && !StringUtils.isEmpty(id)){
            return events.stream().filter(x -> x.getId().equals(id)).findAny().orElse(null);
        }
        return null;
    }

    public Condition getConditionById(String id){
        if(conditions!=null && conditions.size()>0 && !StringUtils.isEmpty(id)){
            return conditions.stream().filter(x -> x.getId().equals(id)).findAny().orElse(null);
        }
        return null;
    }

    public Node getNodeById(String id){
        if(nodes!=null && nodes.size()>0 && !StringUtils.isEmpty(id)){
            return nodes.stream().filter(x -> x.getId().equals(id)).findAny().orElse(null);
        }
        return null;
    }

    public Line getLineById(String id){
        if(lines!=null && lines.size()>0 && !StringUtils.isEmpty(id)){
            return lines.stream().filter(x -> x.getId().equals(id)).findAny().orElse(null);
        }
        return null;
    }

}
